﻿Imports System.Data.SqlClient

Public Class Frm_Rech_AchatEquipe

    Private Sub Frm_Rech_AchatEquipe_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_AchatEquipement.Enabled = True
        Frm_Paiem_achat_Equip.Enabled = True
    End Sub

    Private Sub Frm_Rech_AchatEquipe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_selectionnez.SelectedIndex = 0
    End Sub

    Private Sub txt_mot_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_mot.TextChanged

        Dim mot As String = ""
        If comb_selectionnez.SelectedItem = "Nom fournisseur" Then
            mot = "Nom"
        ElseIf comb_selectionnez.SelectedItem = "Prenom fournisseur" Then
            mot = "Prenom"
        ElseIf comb_selectionnez.SelectedItem = "Numéro bon d'achat" Then
            mot = "numBon"
        ElseIf comb_selectionnez.SelectedItem = "Date d'achat" Then
            mot = "dateAchat"
        End If

        Try
            List_tous.Items.Clear()
            Dim d As String = ""
            Cmd = New SqlCommand("select achatEquipFour.*,Fournisseus.Nom,Fournisseus.prenom,Categorie from achatEquipFour,Fournisseus where achatEquipFour.idFour=Fournisseus.Id_Fournisseur and " & mot & " like '%" & txt_mot.Text & "%'", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                d = ""
                If Dr("dateAchat") <> "1900-01-01" Then
                    d = Dr("dateAchat")
                End If
                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom") & "  " & Dr("Prenom"), Dr("Categorie"), Dr("numBon"), d, Dr("idAchat")})
                List_tous.Items.Add(Line)
            Loop
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        If txt_mot.Text = "" Then
            List_tous.Items.Clear()
        End If

    End Sub

    Private Sub comb_selectionnez_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_selectionnez.SelectedIndexChanged
        txt_mot.Clear()
    End Sub

    Private Sub btn_selectionnez_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_selectionnez.Click
        If List_tous.SelectedIndices.Count > 0 Then
            If rech = "paiement" Then
                Frm_Paiem_achat_Equip.selectionner(CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(4).Text))
            ElseIf rech = "achat" Then
                Frm_AchatEquipement.Selectionner(CInt(List_tous.Items(List_tous.SelectedIndices(0)).SubItems(4).Text))
            End If

            Me.Close()
        End If
    End Sub
End Class